package com.example.demo.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

/**
 * @Author lzs
 * @Date: 2022/11/21/ 9:46
 * @Description
 */
@Data
@NoArgsConstructor
public class Result<T>{
    private T data;
    private String code;
    private String msg;

    public Result(T data) {
        this.data = data;
    }


    /**
     * 返回成功
     */
    public static Result ok(){
        Result result = new Result();
        result.setCode("200");
        result.setMsg("成功");
        return result;
    }
    /**
     * 返回成功
     */
    public static<T> Result<T> ok(T data){
        Result<T> result = new Result<>(data);
        result.setCode("200");
        result.setMsg("成功");
        return result;
    }

    /**
     * 返回失败
     */
    public static Result error(String code, String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        return result;
    }
}
